package dayPractice.六十四位整数乘法;

import java.util.Scanner;

/**
 * a * b
 *
 * a + a + ... + a   共b个a
 *
 * a * 1 = a
 * a * 2 = 2a
 * a * 4 = 4a
 * a * 8 = 8a
 *
 * a * (2 ^ k)
 * @author Summerday
 */
public class M {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long p = sc.nextLong();
        long res = 0;
        while( b != 0){
            if((b & 1) == 1){
                res = (res + a) % p;
            }
            b >>= 1;
            a = a * 2 % p;
        }
        System.out.println(res);
    }
}
